<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">

<head th:replace="admin/_fragments :: head(~{::title})">
    <title>blogs-input</title>
</head>

<body>

    <!-- 导航 -->
    <nav th:replace="admin/_fragments :: menu(2)" >
    </nav>

    <div id="new-list" class="ui attached pointing menu">
        <div class="m-container">
            <div class="ui menu">
                <a th:href="@{/admin/blogs/input}" class="active item">新增</a>
                <a th:href="@{/admin/blogs}" class="item">列表</a>
            </div>
        </div>
    </div>

    <!-- 中间 -->
    <div id="main" class="m-padding-tb-large ">
        <div class="ui grey m-container">
            <form id="blog-form" th:object="${blog}" th:action="@{/admin/blogs}" method="post" class="ui form">
                <input type="hidden" name="published">
                <input type="hidden" name="id" th:value="*{id}">
                <div class="required field">

                    <div class="ui left labeled input">
                        <div class="ui selection compact teal basic dropdown label">
                            <input type="hidden" name="flag" th:value="*{flag}">
                            <i class="dropdown icon"></i>
                            <div class="text">原创</div>
                            <div class="menu">
                                <div class="item" data-value="原创">原创</div>
                                <div class="item" data-value="转载">转载</div>
                                <div class="item" data-value="翻译">翻译</div>
                            </div>
                        </div>
                        <input type="text" name="title" placeholder="标题" th:value="*{title}">
                    </div>
                </div>

                <div class="required field">
                    <div >
                        <textarea name="introduce" id="introduce" placeholder="博客介绍" th:text="*{introduce}">
                        </textarea>
                    </div>
                </div>

                <div class="required field">
                    <div id="md-content" style="z-index: 1 !important;">
                        <textarea name="content" id="content" placeholder="博客内容" th:text="*{content}" style="display: none;">
                        </textarea>
                    </div>
                </div>

                <div class="two fields">
                    <div class="required field">
                        <div class="ui left labeled input">
                            <label class="ui compact teal basic label">分类</label>
                            <div class="ui fluid selection dropdown">
                                <input type="hidden" name="typeId" th:value="*{typeId}">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu">
                                    <div class="item" th:each="type : ${types}" th:data-value="${type.id}" th:text="${type.name}">错误日志</div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="required field">
                        <div class="ui left labeled input">
                            <label class="ui compact teal basic label">标签</label>
                            <div class="ui fluid multiple search selection dropdown">
                                <input type="hidden" name="tagIds" th:value="*{tagIds}">
                                <i class="dropdown icon"></i>
                                <div class="default text">标签</div>
                                <div class="menu">
                                    <div class="item" th:each="tag : ${tags}" th:data-value="${tag.id}" th:text="${tag.name}">Java</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="required field">
                    <div class="ui left labeled input">
                        <label for="firstPicture" class="ui teal basic label">首图</label>
                        <input type="text" id="firstPicture" name="firstPicture" placeholder="首图引用地址" th:value="*{firstPicture}">
                    </div>
                </div>

                <div class="inline grey fields white">
                    <div class="field">
                        <dov class="ui checkbox">
                            <input type="checkbox" id="recommend" name="recommend" class="hidden" th:checked="*{recommend}">
                            <label for="recommend" class="white">推荐</label>
                        </dov>
                    </div>
                    <div class="field">
                        <dov class="ui checkbox">
                            <input type="checkbox" id="shareStatement" name="shareStatement" class="hidden" th:checked="*{shareStatement}">
                            <label for="shareStatement" class="white">转载声明</label>
                        </dov>
                    </div>
                    <div class="field">
                        <dov class="ui checkbox">
                            <input type="checkbox" id="appreciation" name="appreciation" class="hidden" th:checked="*{appreciation}">
                            <label for="appreciation" class="white">赞赏</label>
                        </dov>
                    </div>
                    <div class="field">
                        <dov class="ui checkbox">
                            <input type="checkbox" id="commentabled" name="commentabled" class="hidden" th:checked="*{commentabled}">
                            <label for="commentabled" class="white">评论</label>
                        </dov>
                    </div>
                </div>

                <div class="ui error message"></div>

                <div class="ui right aligned m-container">
                    <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                    <button type="button" id="save-btn" class="ui green button">保存</button>
                    <button type="button" id="publish-btn" class="ui teal button">发布</button>
                </div>

            </form>
        </div>
    </div>

    <!-- 底部 -->
    <footer th:replace="admin/_fragments :: footer">
    </footer>

    <th:block th:replace="admin/_fragments :: script">
    </th:block>
    <script>
        $(".btn-sidebar").click(function() {
            $(".m-item").toggleClass("m-mobile-hide");
        });

        $(".ui.dropdown").dropdown({
            on: "click"
        });

        $(".ui.form").form({
            fields: {
                title: {
                    identifier: "title",
                    rules: [{
                        type: "empty",
                        prompt: "请输入标题"
                    }]
                },
                content: {
                    identifier: "content",
                    rules: [{
                        type: "empty",
                        prompt: "请输入内容"
                    }]
                },
                typeId: {
                    identifier: "typeId",
                    rules: [{
                        type: "empty",
                        prompt: "请选择类型"
                    }]
                },
                firstPicture: {
                    identifier: "firstPicture",
                    rules: [{
                        type: "empty",
                        prompt: "请输入首图地址"
                    }]
                },
                introduce: {
                    identifier: "introduce",
                    rules: [{
                        type: "empty",
                        prompt: "请输入简介"
                    }]
                },
                tagIds: {
                    identifier: "tagIds",
                    rules: [{
                        type: "empty",
                        prompt: "请选择标签"
                    }]
                }
            }
        });

        var contentEditor;

        $(function() {
            contentEditor = editormd("md-content", {
                width: "100%",
                height: 640,
                syncScrolling: "single",
                // path: "../../static/lib/editormd/lib/"
                path: "/lib/editormd/lib/"
            });
        });

        $("#save-btn").click(function () {
            $("[name='published']").val(false);
            $("#blog-form").submit();
        });
        $("#publish-btn").click(function () {
            $("[name='published']").val(true);
            $("#blog-form").submit();
        });

        $(function(){
            getHeight();
        })
        function getHeight(){
            var height = $("nav").height()+$("#new-list").height()+$("#main").innerHeight()+$("footer").height();
            if(height>$(window).height()){
                $("footer").removeClass("m-stick-bottom");
            }else {
                $("footer").addClass("m-stick-bottom");
            };
        }
    </script>
</body>

</html>
